<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../query.header.jsp"%>
<style type="text/css">
#_body {
	background: #FFFFFF url() repeat-x;
}
</style>

<script type="text/javascript">
var _projectPageIndex = 0, _projectPageSize = 20, _projectCurrentCount = 0, _projectTotalCount = 0;

function _projectGetParameter(){
	return {
		start: _projectPageIndex,
		limit: _projectPageSize,
		customerId: $("#customerId").val(),
		specialId: $("#specialId").val(),
		year: $("#year").val(),
		close: 0,
		name: $("#_projectName").val()
	};
}

function _projectList(){
	$.ajax({
    	type: "GET",
    	cache: false,
    	url: ctx + "/biz/project/list.json",
    	data: _projectGetParameter(),
    	dataType:"json",
    	success:function(json) {
    		if (!json.succeed) {
    			$.alert(json.message);
    			return;
    		}
			_projectBuildList(json.data);
    	},
		error: function(message) {
			$.alert(message);
		}
	});
}

function _projectRefresh(){
	_projectPageIndex = 0;
	_projectCurrentCount = 0;
	_projectTotalCount = 0;
	
	$("#_projectListTable").find("tbody").html("");
	$("#_prjectMoreDiv").show();
	_projectList();
}

function _projectMoreData(){
	_projectPageIndex++;
	_projectList();
}

function _projectBuildList(data){
	if(data.length == 0){
		$("#_prjectMoreDiv").hide();
		return;
	}
	_projectCurrentCount += data.length;
	if(data.length < _projectPageSize){
		$("#_prjectMoreDiv").hide();
	} else {
		$("#_prjectMoreDiv").show();
	}
	$(data).each(function(index, item) {
		_projectBuildTd(item).appendTo($("#_projectListTable").find("tbody"));
	});
}

function _projectBuildTd(item){
	var taskEle = $("#_projectListTemplate").clone();
	taskEle.find("tr").attr("id", "item" + item.id);
	var tdList = taskEle.find("td");
	$(tdList.get(0)).find("input").data("item", item);
	$(tdList.get(1)).text(item.name);
	$(tdList.get(2)).text(item.organName);
	$(tdList.get(3)).text(item.areaName);
	$(tdList.get(4)).text(item.customerName);
	$(tdList.get(5)).text(item.specialName);
	$(tdList.get(6)).text(item.year);	
	return taskEle.find("tr");
}

  
function _beforeConfirm(callback) {
 	var selectedItems = $("#_projectListTable").find(":radio:checked");
	if (selectedItems.length == 0) {
		$.alert("请选择项目！");
		return false;
	}
	callback(selectedItems.data("item"));
	return true;
}
 
$("#_projectList").ready(function(){
	_projectRefresh();
});

</script>

<div id="_projectList">
	<div class="text-right form-inline">
		<form id="searchForm" action="">
			<select name="customerId" id="customerId" class="input-small">
				<option value="">所有客户</option>
				<c:forEach var="customer" items="${customers}">
					<option value="${customer.id}">${customer.name}</option>
				</c:forEach>
			</select>
			<select name="specialId" id="specialId" class="input-small">
				<option value="">所有专业</option>
				<c:forEach var="special" items="${specials}">
					<option value="${special.id}">${special.name}</option>
				</c:forEach>
			</select>	
			<select name="year" id="year" class="input-small">
				<option value="">所有年度</option>
				<c:forEach var="year" begin="2010" end="2050">
					<option value="${year}">${year}</option>
				</c:forEach>
			</select>	
			<input type="text" name="_projectName" id="_projectName" class="input-small" placeholder="请输入名称..."/>
			<a class="btn" href="javascript:;" onclick="_projectRefresh()">查询</a>
		</form>
	</div>

	<table id="_projectListTable" class="table table-striped cms-table">
		<thead>
			<tr>
				<th width="20">&nbsp;</th>
				<th>名称</th>
				<th width="80">分公司</th>
				<th width="50">地区</th>
				<th width="60">客户</th>
				<th width="60">专业</th>
				<th width="40">年度</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	<div class="well cms_more" id="_prjectMoreDiv">
		<a href="javascript:;" onclick="_projectMoreData()"><i class="icon-arrow-down"></i>查看更多...</a>
	</div>

	<table id="_projectListTemplate" class="hide">
	  	<tr>
	  		<td><input type="radio" name="_selectedProject"></td>
		    <td></td>
		    <td></td>
		    <td></td>
		    <td></td>
		    <td></td>
		    <td></td>
	  	</tr>
	</table>
  
</div>
